#pragma once

#include <QtCore/QTimer>
#include <QtGui/QFrame>
#include <QtGui/QListWidget>
#include <QtGui/QPushButton>
#include "DisholDeviceManager.h"

namespace Dishol
{

class QDeviceWidget;

class DisholQDeviceManagerWidget : public QFrame,
								   public Dishol::DeviceManager::Listener
{ 
	Q_OBJECT

public:
	DisholQDeviceManagerWidget( QWidget* parent, Dishol::DeviceManager* deviceManager );
	virtual ~DisholQDeviceManagerWidget();

protected:
	virtual void onDeviceAdded( DeviceManager* deviceManager, Device* device );
	virtual void onDeviceRemoving( DeviceManager* deviceManager, Device* device );
	virtual void onDeviceRemoved( DeviceManager* deviceManager, Device* device );

	Device*						getDeviceFromItem( QListWidgetItem* item ) const;
	QListWidgetItem*			getItemFromDevice( Device* device ) const;
	QDeviceWidget*				getDeviceWidgetFromItem( QListWidgetItem* item ) const;
	
	void						updateDeviceListWidget();

private slots:
	void						onTimerTimeOut();
	void						onListItemDoubleCliked( QListWidgetItem* item );

private:
	Dishol::DeviceManager*		mDeviceManager;
	QTimer*						mTimer;
	QListWidget*				mDeviceListWidget;
	QPushButton*				mStartStopButton;
};

}
